package com.ruoyi.dl.controller;

import java.util.List;

import com.ruoyi.dl.domain.DlRecreation;
import com.ruoyi.dl.service.IDlRecreationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dl.domain.DlGameGrade;
import com.ruoyi.dl.service.IDlGameGradeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 游戏段位Controller
 *
 * @author wangshouli
 * @date 2021-01-04
 */
@Controller
@RequestMapping("/dl/grade")
public class DlGameGradeController extends BaseController {
    private String prefix = "dl/grade";

    @Autowired
    private IDlGameGradeService dlGameGradeService;

    @Autowired
    private IDlRecreationService iDlRecreationService;

    @RequiresPermissions("dl:grade:view")
    @GetMapping()
    public String grade() {
        return prefix + "/grade";
    }

    /**
     * 查询游戏段位列表
     */
    @RequiresPermissions("dl:grade:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DlGameGrade dlGameGrade) {
        startPage();
        List<DlGameGrade> list = dlGameGradeService.newSelectDlGameGradeList(dlGameGrade);
        return getDataTable(list);
    }

    /**
     * 导出游戏段位列表
     */
    @RequiresPermissions("dl:grade:export")
    @Log(title = "游戏段位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DlGameGrade dlGameGrade) {
        List<DlGameGrade> list = dlGameGradeService.selectDlGameGradeList(dlGameGrade);
        ExcelUtil<DlGameGrade> util = new ExcelUtil<DlGameGrade>(DlGameGrade.class);
        return util.exportExcel(list, "grade");
    }

    /**
     * 新增游戏段位
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
        // 游戏
        List<DlRecreation> dlRecreationList = iDlRecreationService.selectDlRecreationList(new DlRecreation());
        modelMap.put("dlRecreationList", dlRecreationList);
        return prefix + "/add";
    }

    /**
     * 新增保存游戏段位
     */
    @RequiresPermissions("dl:grade:add")
    @Log(title = "游戏段位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DlGameGrade dlGameGrade) {
        return toAjax(dlGameGradeService.insertDlGameGrade(dlGameGrade));
    }

    /**
     * 修改游戏段位
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        DlGameGrade dlGameGrade = dlGameGradeService.selectDlGameGradeById(id);
        mmap.put("dlGameGrade", dlGameGrade);
        // 游戏
        List<DlRecreation> dlRecreationList = iDlRecreationService.selectDlRecreationList(new DlRecreation());
        mmap.put("dlRecreationList", dlRecreationList);
        return prefix + "/edit";
    }

    /**
     * 修改保存游戏段位
     */
    @RequiresPermissions("dl:grade:edit")
    @Log(title = "游戏段位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DlGameGrade dlGameGrade) {
        return toAjax(dlGameGradeService.updateDlGameGrade(dlGameGrade));
    }

    /**
     * 删除游戏段位
     */
    @RequiresPermissions("dl:grade:remove")
    @Log(title = "游戏段位", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(dlGameGradeService.deleteDlGameGradeByIds(ids));
    }
}
